package art.yulang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/demo")
public class LoginController {
    @RequestMapping(value = "/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("login")
    public String login(String username, String password, HttpSession session) {
        // 合法用户，信息写入session，同时跳转到系统主页面
        if("admin".equals(username) && "admin".equals(password)) {
            session.setAttribute("username",username + System.currentTimeMillis());
            return "redirect:/index/index";
        }else{
            // 非法用户返回登录页面
            return "redirect:/demo/toLogin";
        }
    }
}
